package com.ita.iosa.service.impl;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.jms.JMSException;

import com.ita.iosa.dao.MerchantDao;
import com.ita.iosa.dao.MerchantStatusDao;
import com.ita.iosa.dao.impl.MerchantDaoImpl;
import com.ita.iosa.dao.impl.MerchantStatusDaoImpl;
import com.ita.iosa.jms.api.AuditPendingMerchant;
import com.ita.iosa.po.Merchant;
import com.ita.iosa.po.MerchantStatus;
import com.ita.iosa.service.AdminManager;

public class AdminManagerImpl implements AdminManager {
	private MerchantDao md = new MerchantDaoImpl();
	private MerchantStatusDao msd = new MerchantStatusDaoImpl();

	@Override
	public List<Merchant> showWaitAuditMerchants() {
		List<Merchant> waitMerchants = new ArrayList<Merchant>();
		List<Integer> waitMids = msd.selectWaitMid();

		if (!waitMids.isEmpty()) {
			for (Integer integer : waitMids) {
				waitMerchants.add(md.selectOneMerchant(integer));
			}

		}

		return waitMerchants;
	}

	@Override
	public List<Merchant> showPassMerchants() {
		List<Merchant> passMerchants = new ArrayList<Merchant>();
		List<Integer> passMids = msd.selectPassMid();

		if (!passMids.isEmpty()) {
			for (Integer integer : passMids) {
				passMerchants.add(md.selectOneMerchant(integer));
			}

		}

		return passMerchants;
	}
	
	@Override
	public List<Merchant> showBlackMerchants() {
		List<Merchant> blackMerchants = new ArrayList<Merchant>();
		List<Integer> blackMids = msd.selectBlackMid();

		if (!blackMids.isEmpty()) {
			for (Integer integer : blackMids) {
				blackMerchants.add(md.selectOneMerchant(integer));
			}

		}

		return blackMerchants;
	}
	
	
	@Override
	public int showWaitSize() {
		HashMap<Integer, Integer> allMerchantStatus = msd.selectAllMerchantStatus();
		int size = 0;
		for (Integer mid : allMerchantStatus.keySet()) {
			if (allMerchantStatus.get(mid) == 0) {
				size++;
			}
		}
		return size;
	}

	@Override
	public boolean AuditMerchant(int mid, boolean isPass) {

		if (isPass) {
			int m = msd.updateMerchantStatus(mid, 1);
		} else {
			int m = msd.updateMerchantStatus(mid, 3);
		}

		return true;
	}

	@Override
	public int blcakMerchant(int mid) {
		return msd.updateMerchantStatus(mid, 2);
	}

	@Override
	public int whiteMerchant(int mid) {
		return msd.updateMerchantStatus(mid, 1);
	}

	@Override
	public Merchant showThisMerchant(int mid) {
		return md.selectOneMerchant(mid);
	}

	@Override
	public HashMap<Integer, Integer> showAllMerchantStatus() {
		return msd.selectAllMerchantStatus();
	}

	

}
